using Emgu.CV;

namespace TestNetCoreEmguCU
{
    public partial class Form1 : Form
    {
        private const string video_url = "rtsp://admin:zckj888888@192.168.1.64:554/h264/ch1/sub/av_stream";
        VideoCapture capture;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            capture = new VideoCapture(video_url);
            capture.ImageGrabbed += Capture_ImageGrabbed;
            capture.Grab();
            capture.Start();
            //capture.Read(Emgu.CV.CvEnum.CapProp.Fps);
            //label1.Text = capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
        }
        int fps = 0;
        DateTime startTime=DateTime.Now;

        private void Capture_ImageGrabbed(object sender, EventArgs e)
        {
            fps++;
            Mat image = new Mat();
            capture.Retrieve(image);
            picCAM.Image = image.ToBitmap();
            TimeSpan ts = DateTime.Now - startTime;
            if (ts.TotalSeconds > 1)
            {
                startTime = DateTime.Now;
                int c = fps;
                this.Invoke(new Action(() =>
                {
                    label1.Text= c.ToString();
                }));
                fps = 0;

            }
            
        }
    }
}
